<?php
namespace Shopiuu\Model;

use Shopiuu\Http\RequestCore;

class Currency extends Model{
    
    public function __construct($accessToken, $endpoint)
    {
        parent::__construct($accessToken, $endpoint);
    }

    /**
     * Create currency
     * @param array $params array(
            [name] => 美元
            [symbol_left] => US$ 
            [symbol_code] => USD
            [symbol_right] => 
            [rate] => 1
            [decimal_points] => 2
            [country_code] => US
            [sort] => 10
            [status] => 1
        )
     * @return ResponseCore
     */
    public function add($params)
    {
        $request = $this->getRequest('/openApi/currency/add');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Modify currency
     * @param array $paramss array(
            [id] => 1
            [name] => 美元
            [symbol_left] => US$ 
            [symbol_code] => USD
            [symbol_right] => 
            [rate] => 1
            [decimal_points] => 2
            [country_code] => US
            [sort] => 10
            [status] => 1
        )
     * @return ResponseCore
     */
    public function update($params)
    {
        $request = $this->getRequest('/openApi/currency/update');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get currency
     * @param array $params array(
        "pagenum"=> 1 //页码
        "pagesize"=> 20 //每页数量
        "search"=> "keywords" //搜索标题
        "symbol_code"=> "USD" //搜索货币符号
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "desc" //排序方式
     )
     * @return ResponseCore
     */
    public function getList($params)
    {
        $request = $this->getRequest('/openApi/currency/lists');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }
    
    /**
     * Delete currency
     * @param array $params array("id"=>"25")
     * @return ResponseCore
     */
    public function delete($params)
    {
        $request = $this->getRequest('/openApi/currency/delete');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

}